//Page Object
import {
  request
} from "../../request/index.js"


Page({
  data: {
    //轮播图数据
    swiperList: [],
    //导航栏数据
    catesList: [],
    //楼层数据
    floorList: []
  },

  //options(Object)
  onLoad: function (options) {
    this.getswiperList();
    this.getcatesList();
    this.getfloorList();
  },
  getswiperList() {
    let _this = this

    request({
      url: '/home/swiperdata'
    })
      .then(result => {
        console.log(result);
        result.data.message.forEach(v => {
          if (v.navigator_url) {
            let boxarr = [];
            let pos = v.navigator_url.indexOf('/');
            let pos_ = v.navigator_url.indexOf('?');
            while (pos > -1) {
              boxarr.push(pos);
              pos = v.navigator_url.indexOf('/', pos + 1);
            }
            let a = v.navigator_url.substring(boxarr[boxarr.length - 1] + 1, pos_)
            let b = v.navigator_url.substring(boxarr[boxarr.length - 2] + 1, boxarr[boxarr.length - 1])
            v.navigator_url = v.navigator_url.replace(a, b)
          }
        })
        _this.setData({
          swiperList: result.data.message
        });
        // _this.setData({
        //   swiperList: result.data.data.filter(item => {
        //     return item.title == "首页轮播图"
        //   })
        // });
        // return request({
        //   url: 'https://api.zbztb.cn/api/public/v1/home/catitems'
        // })
      })
    // .then(result => {
    //   console.log(result);
    // })
  },
  getcatesList() {
    let _this = this
    request({
      url: '/home/catitems'
    })
      .then(result => {
        console.log(result);
        result.data.message.forEach(v => {
          if (v.navigator_url) {
            let boxarr = [];
            let pos = v.navigator_url.indexOf('/');
            while (pos > -1) {
              boxarr.push(pos);
              pos = v.navigator_url.indexOf('/', pos + 1);
            }
            let a = v.navigator_url.substring(boxarr[boxarr.length - 1] + 1, v.navigator_url.length)
            let b = v.navigator_url.substring(boxarr[boxarr.length - 2] + 1, boxarr[boxarr.length - 1])
            v.navigator_url = v.navigator_url.replace(a, b)
          }

        })
        _this.setData({
          catesList: result.data.message
        });
      })
  },
  getfloorList() {
    let _this = this
    request({
      url: '/home/floordata'
    })
      .then(result => {
        console.log(result);
        _this.setData({
          floorList: result.data.message
        });
      })
  }


});